import axios from 'axios'
import { message } from 'antd'
const isDev = process.env.NODE_ENV === 'development'

const devURL = 'http://rap2api.taobao.org/app/mock/244531'
const prodURL = ''

const adminAPI = axios.create({
  baseURL: isDev ? devURL : prodURL,
  timeout: 1000,
})

const commonAPI = axios.create({
  baseURL: isDev ? devURL : prodURL,
  timeout: 1000,
})

// 请求拦截器
adminAPI.interceptors.request.use((config) => {
  // console.log(config)
  config.data = Object.assign({}, config.data, {
    // authToken: window.localStorage.getItem('authToken')
    authToken: 'FE8730d5-b34d-Aba9-E16D-2B8E9C2Dcf4C'
  })
  return config;
})

// 响应拦截器
adminAPI.interceptors.response.use((res) => {
  // console.log('responce', res)
  if (res.data.code === 200) {
    return res.data.data;
  } else {
    // 全局处理错误
    message.loading(res.data.errMsg)
    // console.log('错误')
  }
})

export {
  adminAPI,
  commonAPI
}
